package com.mfs.proxy.client.transfer.http.request;

import java.nio.charset.Charset;

/**
 * Http 请求体
 *
 * @author mfs
 * @date 2023/7/10 22:33
 **/
public class HttpRequestBody {
    /**
     * 解码后的请求体，懒加载，只有主动调用decode后才会解码
     * */
    private String body;
    private byte[] bytes = new byte[0];

    public void setBody(String body) {
        this.body = body;
    }

    public String getBody() {
        return body;
    }

    public byte[] getBytes() {
        return bytes;
    }

    public void setBytes(byte[] bytes) {
        this.bytes = bytes;
    }

    /**
     * 按给定的字符集解码消息体
     * */
    public void decode(Charset charset) {
        body = new String(bytes, charset);
    }

    @Override
    public String toString() {
        return body;
    }
}
